<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    /**
     * 封装json返回格式
     *
     * @param int $code
     * @param string $message
     * @param array $data
     * @return \Illuminate\Http\JsonResponse
     * @author skyjerry <ldwangzhen@gmail.com>
     * @date 2018-07-01
     */
    protected function apiResponse($code = 0, $message = '', $data = [])
    {
        return response()->json(array_merge([
            'code'    => $code,
            'status'  => $code == 200 ? 'success' : 'error',
            'message' => $message,
            'data'    => $data,
        ]));
    }
}
